package com.study

import android.os.Bundle
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.study.commen.BaseActivity
import com.study.commen.dialog.NormalWebDialog
import com.study.viewmodel.HomeViewmodel
import kotlinx.android.synthetic.main.activity_main.*
@Route(path = "/app/main")
class MainActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val viewModel = ViewModelProviders.of(this).get(HomeViewmodel::class.java)
        viewModel.getBanner()
        viewModel.getData()
        viewModel.type.observe(this, Observer {
        })
        viewModel.banner.observe(this, Observer {
            val mutableList: MutableList<String> = arrayListOf()
            for (item in it.data) {
                mutableList.add(item.imagePath)
            }
            banner.setImages(mutableList
            ) { p0, p1 ->
                val newInstance = NormalWebDialog.newInstance(it.data.get(p1).url)
                if (!newInstance.isAdded){
                    newInstance.show(supportFragmentManager,"")
                }
            }
        })
    }

    override fun initLayout(): Int {
        return R.layout.activity_main
    }

    override fun initView() {
    }

    override fun initListener() {
        tvJupm.setOnClickListener { ARouter.getInstance().build("/home/main").navigation() }
    }
}
